// Copyright by Thomas Maierhofer / MSE-iT, Hauptstrasse 32, 88427 Bad Schussenried, Germany
// See licence file of project for licencing details
// Contact: thomas@maierhofer.de
// Important: This is only a Demo Setup. Adjust this to your needs!

#include "stdafx.h"
#include "resource.h"
#include "DemoSetupDialog.h"
#include "Pages\WelcomePage.h"
#include "Pages\FinishPage.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


#if defined _M_IX86 
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 
#elif defined _M_IA64 
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") 
#elif defined _M_X64 
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 
#else 
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 
#endif


// You have to check your installation requirements on your own needs. 
// Don't abort the setup on prerequisites this bootstrapper can install itself, e.g. .NET Framework
bool CheckInstallationRequirements(void)
{
	OSVERSIONINFO osVersionInfo;
	memset(&osVersionInfo,0,sizeof(OSVERSIONINFO));
	osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	::GetVersionEx(& osVersionInfo );

	// needs Windows NT Plattform
	if( osVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT )
	{
		AfxMessageBox( CSetupApp::SetupApp->Messages[PRECHECKS_WINDOWS_NT_FAIL],MB_ICONSTOP | MB_OK);
		return false;
	}

	// needs at least Windows XP 
	if( osVersionInfo.dwMajorVersion < 5 || ( osVersionInfo.dwMajorVersion == 5 && osVersionInfo.dwMinorVersion < 1 ))
	{
		AfxMessageBox( CSetupApp::SetupApp->Messages[PRECHECKS_WINDOWS_XP_FAIL],MB_ICONSTOP | MB_OK);
		return false;
	}

	OSVERSIONINFOEX osVersionInfoEx;
	memset(&osVersionInfoEx,0,sizeof(OSVERSIONINFOEX));
	osVersionInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	::GetVersionEx((LPOSVERSIONINFO) &osVersionInfoEx );

	// needs Service Pack 2 on Windows XP
	if( osVersionInfoEx.dwMajorVersion == 5 && osVersionInfoEx.dwMinorVersion == 1  && osVersionInfoEx.wServicePackMajor < 2)
	{
		AfxMessageBox( CSetupApp::SetupApp->Messages[PRECHECKS_WINDOWS_XP_SP2_FAIL],MB_ICONSTOP | MB_OK);
		return false;
	}
}



// This function is called to init the setup app. 
// You must check your installation requirements here, and return false if they will fail
// It is also up to you to display messages about the failure
// You must create the setup dialog and assign it to CSetupApp::SetupDlg
// And you must add some wizard pages to display.
bool Init( void )
{
	// First attach the zip resource file, because message strings are inside
	CSetupApp::SetupApp->AttachZipResource( IDR_RCDATA1 );


	// Set the prefix for localisation - if you will switch to different language later, do this just again.
	CSetupApp::SetupApp->SetLanguagePrefix("EN");

	// Set the prefix for fallbacks, if resource isn't available in specific language
	CSetupApp::SetupApp->SetNeutralLanguagePrefix("EN");


	// If the installation requirements are not fulfilled -> terminate
	if( ! CheckInstallationRequirements() )
		return false;

	// Create the Setup Dialog after the prerequisit checks
	// IMPORTANT: Always create the Dialog with new. It will be deleted on exit instance
	AfxInitRichEdit2();
	CSetupApp::SetupDlg = new CDemoSetupDialog();

	// Add the needed pages for your Dialog	
	// IMPORTANT: Always create the Pages with new. They will be deleted on dialog destruction
	CSetupApp::SetupDlg->AddPage( new CWelcomePage(),CWelcomePage::IDD);
	CSetupApp::SetupDlg->AddPage( new CFinishPage(),CFinishPage::IDD);

	// return true to begin the wizard processing
	return true;
}


// Declare the real application object, and provide the init function
CSetupApp theApp(Init);